/*******************************************************************************
 * pbanm-m2m(Policy-based Autonomic Management Software for Machine to Machine Setworks in E-health Services)
 * PatientHealthcareSensor.java configures Healthcare sensor devices for patients
 * Developed by Rossi Kamal(rossi@khu.ac.kr), Supervised by Choong Seon Hong(cshong@khu.ac.kr)
 * Networking lab, Department of Computer Engineering, Kyung Hee University, Korea(http://networking.khu.ac.kr)
 * http://code.google.com/p/pbanm-m2m
 *******************************************************************************/

package net.m2m.apbnm.patienthealthcaresensor.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.AbsolutePanel;




import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.StackLayoutPanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.view.client.TreeViewModel;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.TreeViewModel.NodeInfo;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel;
import com.google.gwt.view.client.NoSelectionModel;
import com.google.gwt.view.client.TreeViewModel.DefaultNodeInfo;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.InlineLabel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class PatientHealthcareSensor implements EntryPoint {
	
	private static class Playlist {
	    private final String name;
	    private final List<String> songs = new ArrayList<String>();

	    public Playlist(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a song to the playlist.
	     * 
	     * @param name the name of the song
	     */
	    public void addSong(String name) {
	      songs.add(name);
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the list of songs in the playlist.
	     */
	    public List<String> getSongs() {
	      return songs;
	    }
	  }

	  /**
	   * A composer of classical music.
	   */
	  private static class Composer {
	    private final String name;
	    private final List<Playlist> playlists = new ArrayList<Playlist>();

	    public Composer(String name) {
	      this.name = name;
	    }

	    /**
	     * Add a playlist to the composer.
	     * 
	     * @param playlist the playlist to add
	     */
	    public Playlist addPlaylist(Playlist playlist) {
	      playlists.add(playlist);
	      return playlist;
	    }

	    public String getName() {
	      return name;
	    }

	    /**
	     * Return the rockin' playlist for this composer.
	     */
	    public List<Playlist> getPlaylists() {
	      return playlists;
	    }
	  }
	
	///////////////////////////////////////
	//Cell Tree
	  private static class CustomTreeModel implements TreeViewModel {

		    private final List<Composer> composers;

		    /**
		     * This selection model is shared across all leaf nodes. A selection model
		     * can also be shared across all nodes in the tree, or each set of child
		     * nodes can have its own instance. This gives you flexibility to determine
		     * how nodes are selected.
		     */
		    private final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();

		    public CustomTreeModel() {
		      // Create a database of information.
		      composers = new ArrayList<Composer>();

		      // Add compositions by Beethoven.
		      {
			        Composer beethoven = new Composer("Patient Info");
			        composers.add(beethoven);

			        Playlist concertos = beethoven.addPlaylist(new Playlist("add/edit basic medical info"));
			        Playlist quartets = beethoven.addPlaylist(new Playlist("add/edit healthcare sensor configuration"));
			        
			      }
			      
			      
			      {
				        Composer beethoven = new Composer("Patient Health Record");
				        composers.add(beethoven);

				        Playlist concertos = beethoven.addPlaylist(new Playlist("Emergency View"));
				        Playlist quartets = beethoven.addPlaylist(new Playlist("General View"));
				        
				        
				        
				      }

			      

			      
			      {
				        Composer healthcaresensor = new Composer("Healthcare Sensor Device Settings");
				        composers.add(healthcaresensor);
				        Playlist concertos = healthcaresensor.addPlaylist(new Playlist("ekg sensor"));
				        Playlist concertos1 = healthcaresensor.addPlaylist(new Playlist("blood pressure sensor"));
				        Playlist concertos2 = healthcaresensor.addPlaylist(new Playlist("pulse oximetry sensor"));
				        
				        
				        
				        
				      }

		      // Add compositions by Brahms.
		      
		    }

		    /**
		     * Get the {@link NodeInfo} that provides the children of the specified
		     * value.
		     */
		    public <T> NodeInfo<?> getNodeInfo(T value) {
		      if (value == null) {
		        // LEVEL 0.
		        // We passed null as the root value. Return the composers.

		        // Create a data provider that contains the list of composers.
		        ListDataProvider<Composer> dataProvider = new ListDataProvider<PatientHealthcareSensor.Composer>(
		            composers);

		        // Create a cell to display a composer.
		        Cell<Composer> cell = new AbstractCell<Composer>() {
		          @Override
		          public void render(Context context, Composer value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };

		        // Return a node info that pairs the data provider and the cell.
		        return new DefaultNodeInfo<Composer>(dataProvider, cell);
		      } else if (value instanceof Composer) {
		        // LEVEL 1.
		        // We want the children of the composer. Return the playlists.
		        ListDataProvider<Playlist> dataProvider = new ListDataProvider<Playlist>(
		            ((Composer) value).getPlaylists());
		        Cell<Playlist> cell = new AbstractCell<Playlist>() {
		          @Override
		          public void render(Context context, Playlist value, SafeHtmlBuilder sb) {
		            if (value != null) {
		              sb.appendEscaped(value.getName());
		            }
		          }
		        };
		        return new DefaultNodeInfo<Playlist>(dataProvider, cell);
		      } else if (value instanceof Playlist) {
		        // LEVEL 2 - LEAF.
		        // We want the children of the playlist. Return the songs.
		        ListDataProvider<String> dataProvider = new ListDataProvider<String>(
		            ((Playlist) value).getSongs());

		        // Use the shared selection model.
		        return new DefaultNodeInfo<String>(dataProvider, new TextCell(),
		            selectionModel, null);
		      }

		      return null;
		    }

		    /**
		     * Check if the specified value represents a leaf node. Leaf nodes cannot be
		     * opened.
		     */
		    public boolean isLeaf(Object value) {
		      // The leaf nodes are the songs, which are Strings.
		      if (value instanceof String) {
		        return true;
		      }
		      return false;
		    }

		  }
	

	
	
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		rootPanel.add(absolutePanel, 10, 10);
		absolutePanel.setSize("217px", "711px");
		
		

		TreeViewModel model = new CustomTreeModel();
		CellTree cellTree = new CellTree(model,null);
		cellTree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

		    // Open the first playlist by default.
		TreeNode rootNode = cellTree.getRootTreeNode();
		TreeNode firstPlaylist = rootNode.setChildOpen(0, true);
		firstPlaylist.setChildOpen(0, true);

		
		absolutePanel.add(cellTree, 37, 47);
		cellTree.setSize("150px", "654px");
		
		AbsolutePanel absolutePanel_1 = new AbsolutePanel();
		rootPanel.add(absolutePanel_1, 233, 10);
		absolutePanel_1.setSize("444px", "651px");
		
		Label lblPatientName = new Label("Patient Name:");
		absolutePanel_1.add(lblPatientName, 10, 103);
		
		Label lblInsuranceId = new Label("Insurance ID:");
		absolutePanel_1.add(lblInsuranceId, 10, 143);
		
		Label lblDisease = new Label("Disease:");
		absolutePanel_1.add(lblDisease, 10, 176);
		
		TextBox textBox_2 = new TextBox();
		absolutePanel_1.add(textBox_2, 156, 165);
		
		Label lblSymptoms = new Label("Symptoms");
		absolutePanel_1.add(lblSymptoms, 10, 210);
		
		TextArea textArea = new TextArea();
		absolutePanel_1.add(textArea, 156, 210);
		textArea.setSize("150px", "59px");
		
		Label lblPhysician = new Label("Physician");
		absolutePanel_1.add(lblPhysician, 10, 296);
		
		TextBox textBox_3 = new TextBox();
		absolutePanel_1.add(textBox_3, 156, 285);
		
		Label lblHealthcareSensorConfiguration = new Label("Healthcare Sensor Configuration");
		lblHealthcareSensorConfiguration.addStyleName("gwt-Title-Line");
		absolutePanel_1.add(lblHealthcareSensorConfiguration, 12, 381);
		
		Label lblPatientCondition = new Label("Patient Condition");
		absolutePanel_1.add(lblPatientCondition, 10, 423);
		
		CheckBox chckbxNormal = new CheckBox("Normal");
		absolutePanel_1.add(chckbxNormal, 163, 423);
		
		CheckBox chckbxProne = new CheckBox("Prone");
		absolutePanel_1.add(chckbxProne, 241, 423);
		
		CheckBox chckbxCritical = new CheckBox("Critical");
		absolutePanel_1.add(chckbxCritical, 302, 423);
		
		Label lblBloodPressureevery = new Label("Blood Pressure (interval)");
		absolutePanel_1.add(lblBloodPressureevery, 10, 465);
		
		CheckBox chckbxHour = new CheckBox("1 hour");
		absolutePanel_1.add(chckbxHour, 164, 462);
		
		CheckBox chckbxMin = new CheckBox("5 min");
		absolutePanel_1.add(chckbxMin, 240, 465);
		
		CheckBox chckbxMin_1 = new CheckBox("1 min");
		absolutePanel_1.add(chckbxMin_1, 304, 465);
		
		Label lblHeartRateinterval = new Label("Heart rate(interval)   ");
		absolutePanel_1.add(lblHeartRateinterval, 10, 502);
		
		CheckBox chckbxHour_1 = new CheckBox("1 hour");
		absolutePanel_1.add(chckbxHour_1, 163, 499);
		
		CheckBox chckbxMin_2 = new CheckBox("1 min");
		absolutePanel_1.add(chckbxMin_2, 241, 499);
		
		CheckBox chckbxs = new CheckBox("30s");
		absolutePanel_1.add(chckbxs, 301, 499);
		
		Label lblOxygenLevel = new Label("Oxygen level(interval)");
		absolutePanel_1.add(lblOxygenLevel, 10, 538);
		
		CheckBox chckbxHour_2 = new CheckBox("1 hour");
		absolutePanel_1.add(chckbxHour_2, 163, 535);
		
		CheckBox chckbxMin_3 = new CheckBox("5 min");
		absolutePanel_1.add(chckbxMin_3, 241, 535);
		
		CheckBox chckbxMin_4 = new CheckBox("1 min");
		absolutePanel_1.add(chckbxMin_4, 302, 538);
		
		Button btnSubmit = new Button("Submit");
		absolutePanel_1.add(btnSubmit, 10, 600);
		
		Button btnSave = new Button("Save");
		absolutePanel_1.add(btnSave, 70, 600);
		
		Label lblJooHwaLee = new Label("Joo Hwa Lee");
		absolutePanel_1.add(lblJooHwaLee, 156, 103);
		
		Label label = new Label("30075399146");
		absolutePanel_1.add(label, 156, 143);
		
       
       
       ///////////////////////////////////////////////////////////////////////////
	
	}
}

